#ifndef __THREADPOOL_H__
#define __THREADPOOL_H__
#include "Utils.h"
#include "MysqlFunc.h"
#include "NetWork.h"
#include "Worker.h"

typedef struct ServerQueueNode_s {
    int net_fd;
    int uid;
    int pwd;
    int id;
    struct ServerQueueNode_s* next;
} ServerQueueNode;

typedef struct TaskQueue_s {
    ServerQueueNode * front;
    ServerQueueNode * rear;
    int queue_size;
} TaskQueue;

typedef struct TidArr_s {
    pthread_t * arr;
    int worker_num;
} TidArr;

typedef struct ThreadPool_s{
    TidArr tid_arr;
    TaskQueue task_queue;
    pthread_mutex_t mutex;
    pthread_cond_t cond;
    int exit_flag;
}ThreadPool;

int ThreadPoolInit(ThreadPool *thread_pool, int worker_num);
int EnQueue(TaskQueue *queue, int net_fd, int uid,int pwd,int id);
int DeQueue(TaskQueue *queue);
int Dispatch(MYSQL *mysql_connect,int net_fd, int *pwd_file_id,int command_id,ThreadPool *thread_pool,int listen_fd,int uid,int epoll_fd);

#endif  //__THREADPOOL_H__
